/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.crystalrange.documents.service.impl;

import com.googlecode.genericdao.search.Search;
import com.googlecode.genericdao.search.SearchResult;
import java.util.Date;
import java.util.List;
import org.crystalrange.documents.dao.DocumentGroupDao;
import org.crystalrange.documents.model.DocumentGroup;
import org.crystalrange.documents.service.DocumentGroupService;
import org.crystalrange.model.User;
import org.crystalrange.service.UserService;

/**
 *
 * @author Krzysiek
 */
public class DocumentGroupServiceImpl implements DocumentGroupService {

    private DocumentGroupDao documentGroupDao;
    private UserService userService;

    public DocumentGroupDao getDocumentGroupDao() {
        return documentGroupDao;
    }

    public void setDocumentGroupDao(DocumentGroupDao documentGroupDao) {
        this.documentGroupDao = documentGroupDao;
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }
    
    public DocumentGroup create(String username) {
        User currentUser = this.userService.findByUsername(username);   
        
        DocumentGroup documentGroup = new DocumentGroup();
        documentGroup.setCreatedBy(currentUser);
        documentGroup.setCreatedDate(new Date());
        
        return documentGroup;
    }

    public boolean save(DocumentGroup documentGroup) {
        return this.documentGroupDao.save(documentGroup);
    }

    public boolean remove(DocumentGroup documentGroup) {
        return this.documentGroupDao.remove(documentGroup);
    }

    public DocumentGroup find(Long id) {
        return this.documentGroupDao.find(id);
    }

    public List<DocumentGroup> findAll() {
        return this.documentGroupDao.findAll();
    }

    public SearchResult<DocumentGroup> searchAndCount(Search search) {
        return this.documentGroupDao.searchAndCount(search);
    }

    public List<DocumentGroup> search(Search search) {
        return this.documentGroupDao.search(search);
    }

    public DocumentGroup searchUnique(Search search) {
        return this.documentGroupDao.searchUnique(search);
    }
    
}
